package com.pxl.service.impl;

import com.pxl.dao.UserDao;
import com.pxl.entity.Institution;
import com.pxl.entity.Student;
import com.pxl.entity.Teacher;
import com.pxl.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    public int checkAccount(int id,String pass) {
        if(Integer.toString(id).charAt(4) =='1') {
            if(userDao.selectTeaById(id).getTeaPass().equals(pass)) {
                return 2;
            } else {
                return 0;
            }
        } else {
            if(userDao.selectStuById(id).getStuPass().equals(pass)) {
                return 1;
            } else {
                return 0;
            }
        }
    }

    @Override
    public Student selectStuById(int id) {
        return userDao.selectStuById(id);
    }

    @Override
    public Teacher selectTeaById(int id) {
        return userDao.selectTeaById(id);
    }

    @Override
    public String getStuNameById(int id) {
        return selectStuById(id).getStuName();
    }

    @Override
    public String getTeaNameById(int id) {
        return selectTeaById(id).getTeaName();
    }

    @Override
    public void changeStuPass(Student student) {
        userDao.changeStuPass(student);
    }

    @Override
    public List<Teacher> queryAllTeacher() {
        return userDao.queryAllTeacher();
    }

    @Override
    public List<Institution> queryAllIns() {
        return userDao.queryAllIns();
    }

    /**
     *  修改教师密码
     * @param teacher
     */
    @Override
    public void changeTeaPass(Teacher teacher) {

        userDao.changeTeaPass(teacher);
    }
}
